<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <div class="subtitle t10"><span />基础信息</div>
        <a-row>
          <a-col :span="12">
            <a-form-item label="果园名称" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-input
                :maxLength="15"
                v-decorator="['name', validatorRules.name]"
                placeholder="请输入果园名称"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="果园地址" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <div>
                <a-input
                  v-decorator="['address', validatorRules.address]"
                  style="width: 90%"
                  placeholder="请输入果园地址"
                ></a-input>
                <svg
                  t="1639313532242"
                  @click="loadtion"
                  class="icon"
                  viewBox="0 0 1024 1024"
                  version="1.1"
                  xmlns="http://www.w3.org/2000/svg"
                  p-id="3731"
                  width="20"
                  height="20"
                >
                  <path
                    d="M210.307143 724.056458a422.3956 422.3956 0 0 1 0-599.801752c166.611598-165.672941 436.774117-165.672941 603.385714 0a422.3956 422.3956 0 0 1 0 599.844418L512 1024l-301.692857-299.943542zM512 554.671556a127.998667 127.998667 0 1 0 0-255.997334 127.998667 127.998667 0 0 0 0 255.997334z"
                    fill="#3D3D3D"
                    p-id="3732"
                  ></path>
                </svg>
              </div>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="种植面积(亩)" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-input
                type="number"
                min="0"
                v-decorator="['area', validatorRules.area]"
                placeholder="请输入种植面积（亩）"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="建园时间" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <j-date
                placeholder="请选择建园时间"
                v-decorator="['createdTime']"
                :trigger-change="true"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="种植品种" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <j-multi-select-tag
                type="list_multi"
                v-decorator="['variety', validatorRules.variety]"
                :trigger-change="true"
                dictCode="txpp_tree_varieties,name,id"
                placeholder="请选择种植品种"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="种植株数" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-input type="number" min="0" v-decorator="['treeCount']" placeholder="请输入种植株数" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="物候期" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-input v-decorator="['phenologicalPeriod']" :maxLength="10" placeholder="请输入物候期"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="成熟度" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <j-dict-select-tag
                type="list"
                v-decorator="['maturity', { rules: [{ required: true, message: '请选择成熟度' }] }]"
                :trigger-change="true"
                dictCode="maturity"
                placeholder="请选择成熟度"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-input v-decorator="['principal']" :maxLength="5" placeholder="请输入负责人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="负责人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-input
                :maxLength="11"
                v-decorator="[
                  'phone',
                  { rules: [{ required: true, pattern: /^1\d{10}$/, message: '负责人电话格式不正确' }] },
                ]"
                placeholder="负责人电话"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="果园图片" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <!-- <j-image-upload isMultiple v-decorator="['orchardPictures']"></j-image-upload> -->
              <j-image-upload-custom
                isMultiple
                listType="picture"
                :maxLength="10"
                v-decorator="['orchardPictures', { rules: [{ required: true, message: '请上传果园图片' }] }]"
                tip="最多上传10张，只支持.jpg/.png格式，文件大小小于10M"
                text=""
              ></j-image-upload-custom>
            </a-form-item>
          </a-col>
           <a-col :span="12">
            <a-form-item label="营业时间" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <div 
              v-decorator="['time', { rules: [{ required: true, message: '请填写营业时间' }] }]"
              v-for="(item, index) in businessHours" 
              :key="index" 
              style="margin-bottom: 10px">
                <a-select
                  :value="item.startDayOfWeek"
                  style="width: 85px"
                  @change="handleChange2($event, index)"
                  placeholder="请选择"
                >
                  <a-select-option value="1"> 星期一 </a-select-option>
                  <a-select-option value="2"> 星期二 </a-select-option>
                  <a-select-option value="3"> 星期三 </a-select-option>
                  <a-select-option value="4"> 星期四 </a-select-option>
                  <a-select-option value="5"> 星期五 </a-select-option>
                  <a-select-option value="6"> 星期六 </a-select-option>
                  <a-select-option value="7"> 星期日 </a-select-option>
                </a-select>
                至
                <a-select
                  :value="item.endDayOfWeek"
                  style="width: 85px"
                  @change="handleChange3($event, index)"
                  placeholder="请选择"
                >
                  <a-select-option value="1"> 星期一 </a-select-option>
                  <a-select-option value="2"> 星期二 </a-select-option>
                  <a-select-option value="3"> 星期三 </a-select-option>
                  <a-select-option value="4"> 星期四 </a-select-option>
                  <a-select-option value="5"> 星期五 </a-select-option>
                  <a-select-option value="6"> 星期六 </a-select-option>
                  <a-select-option value="7"> 星期日 </a-select-option>
                </a-select>
                <a-time-picker 
                @change="handleChange4($event, index)"
                v-model="item.startTime" 
                style="width: 100px; margin: 0 10px" 
                format="HH:mm:ss" 
                />
                <a-time-picker 
                v-model="item.endTime" 
                style="width: 100px" 
                format="HH:mm:ss"
                @change="handleChange5($event, index)"
                 />
                <a-icon
                  @click="del(businessHours, index)"
                  type="delete"
                  style="font-size: 18px; margin-left: 10px; color: rgb(217, 48, 38)"
                  v-if="businessHours.length > 1"
                />
              </div>
              <a-button
                v-if="businessHours.length <= 2"
                @click="addbusinessHours"
                icon="plus"
                style="width: 460px; margin: 10px 0"
              ></a-button>
            </a-form-item>
           </a-col>
           </a-row>
           <a-row>
            <a-col :span="12">
             <a-form-item label="果园介绍" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
                <a-textarea
                maxLength="3000"
                :auto-size="{ minRows: 3, maxRows: 6 }"
                v-decorator="['description', { rules: [{ required: true, message: '请输入果园介绍' }] }]"
              ></a-textarea>
             </a-form-item>
            </a-col>
            <a-col :span="12">
            <a-form-item label="果园banner" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <j-file-upload-custom
               accept="jpg,png,gif,MP4"
                listType="text"
                :uploadSize="200"
                isMultiple
                :maxLength="5"
                v-decorator="['banner', { rules: [{ required: true, message: '请上传果园banner' }] }]"
                tip="最多上传5张，文件大小限制200M内，文件类型支持jpg、png、gif、MP4"
                text=""
              ></j-file-upload-custom>
            </a-form-item>
            </a-col>
          </a-row>
        <a-row>
          <div class="subtitle t10"><span />营销信息</div>
          <a-col :span="12">
            <a-form-item label="方针政策" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-textarea
                maxLength="3000"
                :auto-size="{ minRows: 6, maxRows: 10 }"
                v-decorator="['principlesPolicies', { trigger: 'input' }]"
              ></a-textarea>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="果园规划" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 20px">
              <a-textarea
                maxLength="3000"
                :auto-size="{ minRows: 6, maxRows: 10 }"
                v-decorator="['orchardPlanning', { trigger: 'input' }]"
              ></a-textarea>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="display:none">
          <a-col :span="8">
            <a-form-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" style="opacity: 0">
              <a-input v-decorator="['longitude']" placeholder="请输入负责人电话" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" style="opacity: 0">
              <a-input v-decorator="['latitude']" placeholder="请输入负责人电话" disabled></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
    <!-- 子表单区域 -->
    <div class="subtitle1 t10">历年产量</div>
    <j-editable-table
      style="margin-bottom: 20px"
      ref="txppProductionRecords"
      :loading="txppProductionRecordsTable.loading"
      :columns="txppProductionRecordsTable.columns"
      :dataSource="txppProductionRecordsTable.dataSource"
      :maxHeight="300"
      :disabled="formDisabled"
      :rowNumber="false"
      :rowSelection="true"
      :actionButton="true"
    />
    <div class="subtitle1 t10">历年销售额</div>
    <j-editable-table
      style="margin-bottom: 20px"
      ref="txppSalesVolume"
      :loading="txppSalesVolumeTable.loading"
      :columns="txppSalesVolumeTable.columns"
      :dataSource="txppSalesVolumeTable.dataSource"
      :maxHeight="300"
      :disabled="formDisabled"
      :rowNumber="false"
      :rowSelection="true"
      :actionButton="true"
    />
    <a-modal v-model="visible_b" :width="1000" :maskClosable="false" ok-text="确认" cancel-text="取消" @ok="hideModal">
      <a-select
        show-search
        :value="value"
        placeholder="搜索地址"
        style="width: 230px"
        :default-active-first-option="false"
        :show-arrow="false"
        :filter-option="false"
        :not-found-content="null"
        @search="seath"
        @change="handleChange"
      >
        <a-icon slot="suffixIcon" type="search" />
        <a-select-option v-for="d in seathvalueList" :key="d.lonlat">
          {{ d.name }}
        </a-select-option>
      </a-select>
      <div id="divwxMap" style="width: 97%; height: 500px"></div>
      <p>地址：{{ address }}</p>
      <p>经纬度：{{point.length? point[0] + ' , ' + point[1]:'' }}</p>
    </a-modal>
  </a-spin>
</template>

<script>
import pick from 'lodash.pick'
import { AMapManager } from 'vue-amap'
let amapManager = new AMapManager()
import { getAction } from '@/api/manage'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixins'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import JDate from '@/components/jeecg/JDate'
import JImageUpload from '@/components/jeecg/JImageUpload'
import JImageUploadCustom from '@/components/jeecg/JImageUploadCustom'
import JFileUploadCustom from '@/components/jeecg/JFileUploadCustom'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import JEditor from '@/components/jeecg/JEditor'
import moment from 'moment'

export default {
  name: 'TxppOrchardForm',
  mixins: [JEditableTableMixin],
  components: {
    JFormContainer,
    JDate,
    JImageUpload,
    JDictSelectTag,
    JMultiSelectTag,
    JEditor,
    JImageUploadCustom,
    JFileUploadCustom
  },
  data() {
    const self = this
    return {
      businessHours: [
        {
          startDayOfWeek: undefined,
          endDayOfWeek: undefined,
          startTime: undefined,
          endTime: undefined,
        },
      ],
      visible_b: false,
      seathvalueList: [],
      seathvalue: '',
      flag: true,
      wxMap: null,
      searchOption: {
        city: '北京', //搜索范围
        citylimit: true, //限制搜索范围
        currentLng: 116.397829,
        currentLat: 39.907923,
        //city: "", citylimit: false, // 不限制搜索范围搜索，比如想全国搜索
      },
      lng: '',
      lat: '',
      address: '',
      marker: '',
      point: [], //打点经纬度坐标
      amapManager,
      zoom: 12,
      center: [121.48, 31.22],
      events: {
        init: (o) => {
          o.getCity((result) => {
            // this.searchOption.city=result.city
          })
        },
        moveend: () => {},
        zoomchange: () => {},
        click: (e) => {
          self.lng = e.lnglat.lng
          self.lat = e.lnglat.lat
          self.center = [self.lng, self.lat]
          let o = amapManager.getMap()
          if (!self.marker) {
            self.marker = new AMap.Marker({
              position: e.lnglat,
            })
            self.marker.setMap(o)
          }
          self.marker.setPosition(e.lnglat)
          let geocoder = new AMap.Geocoder({})
          geocoder.getAddress(e.lnglat, function (status, result) {
            if (status === 'complete' && result.regeocode) {
              self.address = result.regeocode.formattedAddress
            } else {
              console.log('根据经纬度查询地址失败')
            }
          })
        },
      },
      plugin: [
        'ToolBar',
        {
          pName: 'MapType',
          defaultType: 0,
          events: {
            init(o) {},
          },
        },
      ],
      plugin: [
        {
          pName: 'Geolocation',
          events: {
            init(o) {
              // o 是高德地图定位插件实例
              o.getCurrentPosition((status, result) => {
                if (result && result.position) {
                  self.lng = result.position.lng
                  self.lat = result.position.lat
                  self.address = result.formattedAddress
                  self.center = [self.lng, self.lat]
                  let o = amapManager.getMap()
                  if (!self.marker) {
                    self.marker = new AMap.Marker({
                      position: self.center,
                    })
                    self.marker.setMap(o)
                  }
                  self.marker.setPosition(self.center)
                }
              })
            },
          },
        },
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 4 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 },
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      validatorRules: {
        name: {
          rules: [{ required: true, message: '请输入果园名称' }],
        },
        address: {
          rules: [{ required: true, message: '请输入果园地址' }],
        },
        area: {
          rules: [
            { required: true, message: '请输入种植面积（亩）' },
            { pattern: /^\d{1,9}$|^\d{1,9}[.]\d{1,2}$/, message: '种植面积格式错误' },
          ],
        },
        variety: {
          rules: [{ required: true, message: '请输入种植品种' }],
        },
      },
      refKeys: ['txppProductionRecords', 'txppSalesVolume'],
      tableKeys: ['txppProductionRecords', 'txppSalesVolume'],
      activeKey: 'txppProductionRecords',
      // 历年产量
      txppProductionRecordsTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '年份',
            key: 'particularYear',
            type: FormTypes.select,
            width: '200px',
            placeholder: '请选择${title}',
            defaultValue: '',
            options: [],
          },
          {
            title: '产量（吨）',
            key: 'yieId',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          // {
          //   title: '收录时间',
          //   key: 'collectionTime',
          //   type: FormTypes.date,
          //   width: '200px',
          //   placeholder: '请输入${title}',
          //   defaultValue: '',
          // },
          {
            title: '操作人',
            key: 'operator',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
        ],
      },
      // 历年销售额
      txppSalesVolumeTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '年份',
            key: 'particularYear',
            type: FormTypes.select,
            width: '200px',
            placeholder: '请选择${title}',
            defaultValue: '',
            options: [],
          },
          {
            title: '销售额（万元）',
            key: 'salesVolume',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          // {
          //   title: '收录时间',
          //   key: 'collectionTime',
          //   type: FormTypes.date,
          //   width: '200px',
          //   placeholder: '请输入${title}',
          //   defaultValue: '',
          // },
          {
            title: '操作人',
            key: 'operator',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
        ],
      },
      url: {
        add: '/loquat/txppOrchard/add',
        edit: '/loquat/txppOrchard/edit',
        queryById: '/dome/txppOrchard/queryById',
        txppProductionRecords: {
          list: '/loquat/txppOrchard/queryTxppProductionRecordsByMainId',
        },
        txppSalesVolume: {
          list: '/loquat/txppOrchard/queryTxppSalesVolumeByMainId',
        },
      },
      years: [],
    }
  },
  props: {
    //流程表单data
    formData: {
      type: Object,
      default: () => {},
      required: false,
    },
    //表单模式：false流程表单 true普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false,
    },
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    },
  },
  mounted() {
    this.flag = false
    setTimeout(() => {
      this.flag = true
    }, 500)
    this.initwxMap()
  },
  created() {
    //如果是流程中表单，则需要加载流程表单data
    this.showFlowData()
    // 获取近30年年份
    const date = new Date()
    const currentYear = date.getFullYear()
    for (let i = 0; i < 30; i++) {
      const year = {
        label: (currentYear - i).toString(),
        value: (currentYear - i).toString(),
      }
      this.years.push(year)
    }
    this.txppProductionRecordsTable.columns[0].options = this.years
    this.txppSalesVolumeTable.columns[0].options = this.years
  },
  methods: {
    addbusinessHours() {
      if (this.businessHours.length <= 2) {
        this.businessHours.push({
          startDayOfWeek: undefined,
          endDayOfWeek: undefined,
          startTime: undefined,
          endTime: undefined,
        })
      }
    },
    handleChange2(e, index) {
      this.businessHours[index].startDayOfWeek = e
      let t = this.businessHours[index]
      if(t.startDayOfWeek&&t.endDayOfWeek&&t.startTime&&t.endTime){
         this.$nextTick(()=>{
          setTimeout(() => {
             this.form.setFieldsValue({'time':this.businessHours})
          });
        })
      }
    },
    handleChange3(e, index) {
      this.businessHours[index].endDayOfWeek = e
        let t = this.businessHours[index]
      if(t.startDayOfWeek&&t.endDayOfWeek&&t.startTime&&t.endTime){
         this.$nextTick(()=>{
          setTimeout(() => {
             this.form.setFieldsValue({'time':this.businessHours})
          });
        })
      }
    },
    handleChange4(e, index) {
        let t = this.businessHours[index]
      if(t.startDayOfWeek&&t.endDayOfWeek&&t.startTime&&t.endTime){
         this.$nextTick(()=>{
          setTimeout(() => {
             this.form.setFieldsValue({'time':this.businessHours})
          });
        })
      }
    },
    handleChange5(e, index) {
      let t = this.businessHours[index]
      if(t.startDayOfWeek&&t.endDayOfWeek&&t.startTime&&t.endTime){
        this.$nextTick(()=>{
          setTimeout(() => {
             this.form.setFieldsValue({'time':this.businessHours})
          });
        })
      }
    },
    del(items, index) {
      items.splice(index, 1)
    },
    add() {
      this.form.resetFields()
      this.businessHoursList = []
      this.txppProductionRecordsTable.dataSource = []
      this.txppSalesVolumeTable.dataSource = []
      this.edit({})
      this.businessHours = [
        {
          startDayOfWeek: undefined,
          endDayOfWeek: undefined,
          startTime: undefined,
          endTime: undefined,
        },
      ]
    },
    initwxMap() {
      // vue项目需要先声明 T = window.T，不然后面无法获取到。
      let that = this
      if (!this.wxMap) {
        var T = window.T
        this.wxMap = new T.Map('divwxMap') // div的id
        // 传参中心点经纬度，以及放大程度，最小1，最大18
      }
      this.wxMap.clearOverLays();
      this.address = ''
      this.point = []
      this.wxMap.centerAndZoom(new T.LngLat(120.188522, 30.473461), 17)
      this.wxMap.on('click', (e) => {
        // that.marker.remove()//清除上一次打点实例
        that.point[0] = e.lnglat.lng
        that.point[1] = e.lnglat.lat
        that.addPoint(that.point)
      })
    },
    addPoint(e) {
      this.reverseGeocodFun(e)
    },
    // 逆地理坐标查询
    reverseGeocodFun(data) {
      this.$axios({
        method: 'get',
        url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${data[0]},'lat':${data[1]},'ver':1}&type=geocode&tk=c494b08abe12337f37b9e707363fed10`,
      }).then((res) => {
        if (res.status === 200) {
          this.address = res.data.result.formatted_address
          this.point[0] = res.data.result.location.lon
          this.point[1] = res.data.result.location.lat
          this.wxMap.clearOverLays()
          //创建标注对象
          var marker = new T.Marker(new T.LngLat(res.data.result.location.lon, res.data.result.location.lat))
          //向地图上添加标注
          this.wxMap.addOverLay(marker)
        } else {
          console.log(res.statusText)
        }
      })
    },
    handleChange(e) {
      let gh = e.split(',')
      this.wxMap.centerAndZoom(new T.LngLat(gh[0], gh[1]), 17)
      this.wxMap.clearOverLays()
      //创建标注对象
      var marker = new T.Marker(new T.LngLat(gh[0], gh[1]))
      //向地图上添加标注
      this.wxMap.addOverLay(marker)
    },
    seath(val) {
      this.$axios({
        method: 'get',
        url: `https://api.tianditu.gov.cn/search?postStr={"keyWord":'${val}',"level":"11","mapBound":"116.04577,39.70307,116.77361,40.09583","queryType":"1","count":"20","start":"0"}&type=query&tk=c494b08abe12337f37b9e707363fed10`,
      }).then((res) => {
        if (res.status == 200 && res.data.area) {
          this.seathvalueList = [res.data.area]
        } else if (res.status == 200 && res.data.pois) {
          res.data.pois.forEach((i) => {
            i.lonlat = i.lonlat.split(' ').join(',')
          })
          this.seathvalueList = res.data.pois
        }
      })
    },
    loadtion() {
      this.visible_b = true
      setTimeout(() => {
        this.initwxMap()
      }, 1000)
    },
    hideModal() {
      this.visible_b = false
      this.seathvalue = ''

      this.form.setFieldsValue({
        address: this.address,
        longitude: this.point[0],
        latitude: this.point[1],
      })
    },
    addBefore() {
      this.form.resetFields()
      this.businessHoursList = []
      this.txppProductionRecordsTable.dataSource = []
      this.txppSalesVolumeTable.dataSource = []
    },
    getAllTable() {
      let values = this.tableKeys.map((key) => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      let orchardPictures = []
      if (this.model.orchardPicturesList) {
        this.model.orchardPicturesList.forEach((i) => {
          orchardPictures.push(i.picyurRoute)
        })
        this.model.orchardPictures = orchardPictures
      }
      if (this.model.businessHoursList && this.model.businessHoursList.length > 0) {
        let rows = []
        this.model.businessHoursList.forEach((item, index) => {
          rows.push({
            startTime: this.model.businessHoursList[index].startTime
              ? moment(this.model.businessHoursList[index].startTime, 'HH:mm:ss')
              : undefined,
            endTime: this.model.businessHoursList[index].endTime
              ? moment(this.model.businessHoursList[index].endTime, 'HH:mm:ss')
              : undefined,
            startDayOfWeek: this.model.businessHoursList[index].startDayOfWeek
              ? this.model.businessHoursList[index].startDayOfWeek
              : undefined,
            endDayOfWeek: this.model.businessHoursList[index].endDayOfWeek
              ? this.model.businessHoursList[index].endDayOfWeek
              : undefined,
          })
        })
        this.businessHours = rows
      }
      let fieldval = pick(
        this.model,
        'businessHours',
        'maturity',
        'info',
        'name',
        'address',
        'longitude',
        'latitude',
        'createdTime',
        'area',
        'treeCount',
        'variety',
        'phenologicalPeriod',
        'principal',
        'phone',
        'description',
        'banner',
        'orchardPictures',
        'marketingInformation',
        'principlesPolicies',
        'orchardPlanning'
      )
      this.$nextTick(() => {
        console.log(this.businessHours);
        if(this.businessHours[0].endDayOfWeek&&this.businessHours[0].endTime&&this.businessHours[0].startDayOfWeek&&this.businessHours[0].startTime){
           this.form.setFieldsValue({'time':this.businessHours})
           this.form.setFieldsValue(fieldval)
        }else{
           this.form.setFieldsValue({'time':undefined})
           this.form.setFieldsValue(fieldval)
        }
      })
      // 加载子表数据
      if (this.model.id) {
        let params = { id: this.model.id }
        this.requestSubTableData(this.url.txppProductionRecords.list, params, this.txppProductionRecordsTable)
        this.requestSubTableData(this.url.txppSalesVolume.list, params, this.txppSalesVolumeTable)
      }
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      const arr = []
      let indexs = []
      this.businessHours.map((item,index) => {
        if (!item.endDayOfWeek || !item.endTime || !item.startDayOfWeek || !item.startTime) {
          arr.push(item)
          indexs.push(index+1)
        }
      })
      if (arr.length) {
        const t = indexs.join(',')
        this.$message.warning(`请填写完整的第${t}条营业时间`)
      } else {
        let businessHoursArr = []
        this.businessHours.forEach((i) => {
          businessHoursArr.push({
            startTime: i.startTime ? moment(i.startTime).format('HH:mm:ss') : undefined,
            endTime: i.endTime ? moment(i.endTime).format('HH:mm:ss') :undefined,
            startDayOfWeek: i.startDayOfWeek ? i.startDayOfWeek : undefined,
            endDayOfWeek: i.endDayOfWeek ? i.endDayOfWeek : undefined,
          })
        })
        this.form.setFieldsValue({'time':businessHoursArr})
        return {
          ...main, // 展开
          businessHoursList: businessHoursArr,
          txppProductionRecordsList: allValues.tablesValue[0].values,
          txppSalesVolumeList: allValues.tablesValue[1].values,
        }
      }
    },
    //渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId }
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result)
          }
        })
      }
    },
    // validateError(msg){
    //   this.$message.error(msg)
    // },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'businessHours',
          'maturity',
          'info',
          'name',
          'address',
          'longitude',
          'latitude',
          'createdTime',
          'area',
          'treeCount',
          'variety',
          'phenologicalPeriod',
          'principal',
          'phone',
          'description',
          'banner',
          'orchardPictures',
          'marketingInformation',
          'principlesPolicies',
          'orchardPlanning'
        )
      )
    },
  },
}
</script>

<style lang="less" scoped>
/deep/.ant-time-picker-input{
  font-size:12px
}
/deep/ .ant-select-selection__rendered{
  font-size:12px
}
.subtitle {
  color: #000;
  font-weight: 500;
  font-size: 15px;
  span {
    display: inline-block;
    width: 5px;
    height: 20px;
    background: #1890ff;
    vertical-align: middle;
    margin-right: 10px;
  }
  &.t10 {
    margin: 20px 0 30px 0;
  }
}
.subtitle1 {
  color: #000;
  font-weight: 500;
  margin-bottom: 10px;
  font-size: 13px;
  &.t10 {
    margin: 10px 0;
  }
}
.ant-form-item-control {
  line-height: 0px !important;
}
.ant-col-sm-5 {
  width: 100px;
}
.projectstyle {
  .ant-col-sm-16 {
    width: 88%;
    .ant-form-item-control {
      .ant-form-item-children {
        > div {
          width: 95% !important;
        }
      }
    }
  }
  .ant-col-sm-6 {
    width: 110px;
  }
  /deep/.tdt-control-copyright.tdt-control {
    display: none !important;
  }
}
</style>